﻿Imports Microsoft.VisualBasic
Imports System.Collections.Generic

Namespace Pic
    Public Class InlineTable
        Private _TableName As String
        Private _Fields As List(Of String)
        Private _WhereClause As String

        Public Property TableName() As String
            Get
                Return _TableName
            End Get
            Set(ByVal value As String)
                _TableName = value
            End Set
        End Property
        Public Property Fields() As List(Of String)
            Get
                Return _Fields
            End Get
            Set(ByVal value As List(Of String))
                _Fields = value
            End Set
        End Property
        Public Property WhereClause() As String
            Get
                Return _WhereClause
            End Get
            Set(ByVal value As String)
                _WhereClause = value
            End Set
        End Property

        Public Sub New(ByVal TableName_ As String, ByVal Fields_ As List(Of String), ByVal WhereClause_ As String)
            Me.TableName = TableName_
            Me.Fields = Fields_
            Me.WhereClause = WhereClause_
        End Sub

        Public Shared Function InlineQuery(ByVal InlineTables_ As List(Of InlineTable)) As String
            Dim rtrn As String = ""
            For Each it_ As InlineTable In InlineTables_
                If rtrn <> "" Then
                    rtrn &= " ,"
                End If
                rtrn &= "(Select " & ReturnFields(it_.Fields) & " from " & it_.TableName & " where " & it_.WhereClause & " ) "
            Next
            Return rtrn
        End Function
        Private Shared Function ReturnFields(ByVal Fields_ As List(Of String)) As String
            Dim rtrn_ As String = ""
            For Each f_ As String In Fields_
                If rtrn_ <> "" Then
                    rtrn_ &= ","
                End If
                rtrn_ &= f_
            Next
            Return rtrn_
        End Function
    End Class
End Namespace

